home *** CD-ROM | disk | FTP | other *** search
/ FANTA 97 / FANTA97A (backup).iso / FRONTPAG.SX / fp_install.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1997-09-18  |  51KB  |  2,045 lines

  1. #! /bin/sh
  2. #
  3. # Copyright 1996 Microsoft Corporation -- All Rights Reserved.
  4. #
  5. # $Revision: 1.29 $
  6. # $Date: 1997/09/16 01:16:00 $
  7. #
  8.  
  9.  
  10. step1()
  11. {
  12.  echo 
  13.  echo "Step 1.  Setting Up Installation Environment" 
  14.  echo 
  15.  
  16.  checkuser || error                 # Check to make sure we are root
  17.  banner
  18.  usrlocalexists || error            # Check to make sure that /usr/local exists
  19.  checkforaccess || error            # Check for RWX access to /usr/local
  20.  wheretoinstall || error            # Find out where to install the extensions
  21.  
  22. }
  23.  
  24. step2()
  25. {
  26.  echo 
  27.  echo "Step 2.  Untarring the Extensions and Checking Protections" 
  28.  echo 
  29.  
  30.  untarext   || error                # Untar the extensions
  31.  currentversionlink || error        # Create currentversion link
  32.  
  33. }
  34.  
  35. step3()
  36. {
  37.  echo 
  38.  echo "Step 3.  Upgrading/Installing the extensions" 
  39.  echo 
  40.  
  41.  upgradeexistingservers || error    # Check to see if servers need upgrading
  42.  chownexistingservers || error     
  43.  installrootweb || error            # Install the root web
  44.  installnewsubwebs $PORT || error   # Install new servers
  45.  installvirtualwebs || error        # Install any virtual webs
  46.  
  47. }
  48.  
  49. initialize()
  50. {
  51.   VERSION="3.0"
  52.   PATH=".:/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/etc:/usr/bsd"
  53.   INSTALLDIRDEFAULT="/usr/local/frontpage"
  54.  
  55. case "`echo 'x\c'`" in
  56.    'x\c')   echo="echo -n"    nnl= ;;      #BSD
  57.    x)       echo="echo"       nnl="\c" ;;  # Sys V
  58.    *)       echo "$0 quitting:  Can't set up echo." ; exit 1 ;;
  59. esac
  60.  
  61.  TAB="    "
  62.  system=`uname -a`
  63.  
  64.  case "$system" in
  65.      OSF1*)           machine="alpha" ;;
  66.      Linux*)          machine="linux" ;;
  67.      HP-UX*)          machine="hp700" ;;
  68.      AIX*)            machine="rs6000" ;;
  69.      IRIX*)           machine="sgi" ;;
  70.      SunOS*5.*sun4*)  machine="solaris" ;;
  71.      SunOS*4.*sun4*)  machine="sunos";;
  72.      SunOS*sun3*)     machine="sunos" ;;
  73.      *BSD/OS?3.0*)    machine="bsdi3" ;;
  74.      BSD/OS*)         machine="bsdi" ;;
  75.      SCO_SV*)         machine="sco5" ;;
  76.      *)               echo "ERROR:  Unsupported platform!  Uname is $system." 
  77.                       return 1
  78.                       ;;
  79.  esac
  80.  
  81.  awk=awk
  82.  lsg="ls -ld"
  83.  
  84.  case "$machine" in
  85.       sunos) awk=nawk
  86.              lsg="ls -ldg"
  87.              ;;
  88.     solaris) awk=nawk ;;
  89.         sgi) awk=nawk ;;
  90.  esac
  91.  
  92. }
  93.  
  94. checkuser()
  95. {
  96.  #
  97.  # Make sure we are not running as root.
  98.  #
  99.  
  100. whoami=`whoami 2>/dev/null` || whoami=`/usr/bin/id | sed -e ' s/).*//; s/^.*(//;'`
  101.  retval=0
  102.  
  103.  echo "Setting umask 002" 
  104.  umask 002
  105.  
  106.  if [ $whoami != "root" ]
  107.  then
  108.     echo "ERROR:  Logged in as $whoami.  Must be root to do this installation!"
  109.     retval=1
  110.  else
  111.     echo "Logged in as root." 
  112.  fi
  113.  
  114.  return $retval
  115.  
  116. }
  117.  
  118. banner()
  119. {
  120. cat <<EOF
  121.  
  122.  
  123.  fp_install.sh
  124.  
  125.  Revision$Revision: 1.29 $dummy
  126.  Date$Date: 1997/09/16 01:16:00 $dummy
  127.  
  128. This script will step the user through upgrading existing and installing 
  129. new servers and webs.  As with any software installation, a backup should be
  130. done before continuing.  It is recommended that the FrontPage installation
  131. directory, server configuration file directory, and all web content be 
  132. backed up before continuing with this installation.
  133.  
  134. EOF
  135.  
  136.  myprompt 'yYnN' "Are you satisfied with your backup of the system (y/n)" "N"
  137.  if [ $answer = n ] || [ $answer = N ]
  138.  then
  139.     exit 0
  140.  fi
  141.  echo
  142.  
  143.  return 0
  144. }
  145.  
  146. myprompt()
  147. {
  148.  answer="|"
  149.  until echo $1 | grep $answer >/dev/null
  150.  do
  151.     $echo "${2} [${3}]?  ${nnl}" 
  152.     read answer
  153.     if [ "$3" != "" ] && [ "$answer" = "" ]
  154.     then
  155.        answer=$3
  156.     fi
  157.  done
  158. }
  159.  
  160. getpassword()
  161. {
  162.  prompt=$1
  163.  PASSWORD=""
  164.  until [ "$PASSWORD" != "" ]
  165.  do
  166.     $echo "$prompt:  ${nnl}" 
  167.     stty -echo
  168.     read password1
  169.     stty echo
  170.     echo
  171.     $echo "Re-enter $prompt:  ${nnl}" 
  172.     stty -echo
  173.     read password2
  174.     stty echo
  175.     echo 
  176.     if [ "$password1" = "$password2" ]
  177.     then
  178.         PASSWORD=$password1
  179.     fi
  180.  done
  181.  
  182.  return 1
  183. }
  184.  
  185. usrlocalexists()
  186. {
  187.  #
  188.  # Now lets make sure that /usr/local exists.
  189.  #
  190.  
  191.  localdir="/usr/local"
  192.  prot=755
  193.  retval=0
  194.  
  195.  if [ ! -d "$localdir" ]
  196.  then
  197.     myprompt 'yYnN' "$localdir does not exist.  Would you like to create it (y/n)" "Y"
  198.     if [ $answer = y ] || [ $answer = Y ]
  199.     then
  200.        echo "Creating $localdir" 
  201.        if mkdir "$localdir"
  202.        then
  203.           echo "Directory $localdir has been created." 
  204.           if chmod "$prot" "$localdir"
  205.           then 
  206.              echo "Directory $localdir chmoded to $prot." 
  207.           else
  208.              echo "ERROR:  Unable to chmod $localdir to $prot." 
  209.              retval=1
  210.           fi  
  211.        else
  212.           echo "ERROR:  Unable to create $localdir!" 
  213.           retval=1
  214.        fi
  215.     else
  216.        echo "ERROR:  Directory $localdir must exist!" 
  217.        retval=1
  218.     fi
  219.  else
  220.     if [ ! -d "$localdir" ]
  221.     then
  222.        echo "ERROR:  $localdir exists but is not a directory!" 
  223.        retval=1
  224.     else
  225.        echo "Directory $localdir exists." 
  226.     fi
  227.  fi
  228.  
  229.  return $retval
  230.  
  231. }
  232.  
  233.  
  234. checkforaccess()
  235. {
  236.  #
  237.  # Make sure that we have the correct access to /usr/local
  238.  #
  239.  
  240.  retval=0
  241.  
  242.  #
  243.  # Check to make sure that we have read access to the directory
  244.  #
  245.  comma=""
  246.  if [ ! -r /usr/local ]
  247.  then
  248.     noaccess="Read"
  249.     comma=", "
  250.  fi
  251.  
  252.  #
  253.  # Check to make sure that we have write access to the directory
  254.  #
  255.  if [ ! -w /usr/local ]
  256.  then
  257.     noaccess="$noaccess${comma}Write"
  258.     comma=", "
  259.  fi
  260.  
  261.  #
  262.  # Check to make sure that we have execute access to the directory
  263.  #
  264.  if [ ! -x /usr/local ]
  265.  then
  266.     noaccess="$noaccess${comma}Execute"
  267.  fi
  268.  
  269.  if  [ "$noaccess" != "" ]
  270.  then
  271.     echo "ERROR:  Root does not have $noaccess access to /usr/local!" 
  272.     retval=1
  273.  else
  274.     echo "Root has necessary access to /usr/local." 
  275.  fi
  276.  
  277.  return $retval
  278.  
  279. }
  280.  
  281. wheretoinstall()
  282. {
  283.  #
  284.  # Find out where to install the extensions and create directory and/or link
  285.  # as necessary.
  286.  #
  287.  
  288.  retval=0
  289.  
  290.  echo 
  291.  echo "Where would you like to install the FrontPage Extensions.  If you" 
  292.  echo "select a location other than /usr/local/frontpage/ then a symbolic" 
  293.  echo "link will be created from /usr/local/frontpage/ to the location that" 
  294.  echo "is chosen." 
  295.  echo 
  296.  $echo "FrontPage Extensions directory [/usr/local/frontpage/]:  ${nnl}" 
  297.  read installdir
  298.  
  299.  if [ "$installdir" = "" ]
  300.  then
  301.     installdir=$INSTALLDIRDEFAULT
  302.  fi
  303.  installdir=`dirname $installdir`/`basename $installdir`/
  304.  
  305.  if [ ! -d "$installdir" ]
  306.  then
  307.     echo "Creating $installdir" 
  308.     if mkdir "$installdir"
  309.     then
  310.        echo "Directory $installdir has been created." 
  311.        if chmod "$prot" "$installdir"
  312.        then 
  313.           echo "Directory $installdir chmoded to $prot." 
  314.        else
  315.           echo "ERROR:  Unable to chmod $installdir to $prot." 
  316.           retval=1
  317.        fi  
  318.     else
  319.        echo "ERROR:  Unable to create $installdir!" 
  320.        retval=1
  321.     fi
  322.  else
  323.     echo "WARNING:  Directory $installdir already exists." 
  324.     echo "Installation will overwrite existing files." 
  325.     echo 
  326.  
  327.     myprompt 'yYnN' "Continue the installation (y/n)" "N"
  328.     echo 
  329.     if [ $answer = n ] || [ $answer = N ]
  330.     then
  331.        exit 0
  332.     fi
  333.  fi
  334.  
  335.  if [ "$installdir" != "/usr/local/frontpage/" ]
  336.  then
  337.     if [ ! -d "/usr/local/frontpage" ]
  338.     then
  339.        if ln -s "$installdir" "/usr/local/frontpage"
  340.        then
  341.           echo "ERROR:  Unable to  snap link /usr/local/frontpage --> $installdir!" 
  342.           retval=1
  343.        else
  344.           echo "Snapped link /usr/local/frontpage --> $installdir"        
  345.        fi
  346.     else
  347.        echo "ERROR:  Unable to snap link /usr/local/frontpage --> $installdir, /usr/local/frontpage already exists!" 
  348.        retval=1
  349.     fi
  350.  fi 
  351.  
  352.  return $retval 
  353.  
  354. }
  355.  
  356. untarext()
  357. {
  358.  #
  359.  # Untar the extensions into the installation directory and check permissions
  360.  #
  361.  retval=0
  362.  
  363.  if [ -d "${installdir}version${VERSION}" ]
  364.  then
  365.     echo "Version $VERSION FrontPage Server Extensions found."
  366.     myprompt 'yYnN' "Would you like to overwrite? (y/n)" "Y"
  367.     echo 
  368.     if [ $answer = n ] || [ $answer = N ]
  369.     then
  370.         echo "No need to un-tar the extensions.  Continuing..."
  371.         return $retval
  372.     else
  373.         echo "Looking for tar file..."
  374.     fi
  375.  else
  376.      echo "Version $VERSION FrontPage Server Extensions not found."
  377.      echo "Looking for tar file..."
  378.  fi
  379.  
  380.  vtfile="fp30.$machine.tar"
  381.  echo "Platform is $machine." 
  382.  
  383.  vtfilelocation="`pwd`/"
  384.  
  385.  getextfilename $vtfilelocation $vtfile || return 1
  386.  
  387.  olddir=`pwd`
  388.  cd /usr/local 
  389.  case $fullvtfile in 
  390.      *tar) echo "Untarring file $fullvtfile into /usr/local..." 
  391.            tar -xf $fullvtfile ;;
  392.        *Z) echo "Uncompressing/Untarring file $fullvtfile into /usr/local..."
  393.            zcat $fullvtfile | tar -xf - 
  394.            ;;
  395.       *gz) zcat=""
  396.            while [ "$zcat" = "" ] || [ ! -f "$zcat" ]
  397.            do
  398.                $echo "Where is the zcat which can uncompress gz files? ${nnl}"
  399.                read zcat
  400.                base=`basename zcat`
  401.                case $base in
  402.                   zcat) ;; 
  403.                      *) zcat=`dirname $zcat`/`basename $zcat`/zcat ;;
  404.                esac
  405.            done
  406.            echo "Uncompressing/Untarring file $fullvtfile into /usr/local..."
  407.            $zcat $fullvtfile | tar -xf -
  408.            ;;
  409.         *) echo "ERROR:  Unknown file type: $fullvtfile"
  410.            return 1
  411.            ;;
  412.  esac
  413.  cd $olddir
  414.  
  415.  return $retval
  416.  
  417. }
  418.  
  419. getextfilename()
  420. {
  421.  vtfilelocation=$1
  422.  vtfile=$2
  423.  fullvtfile="${vtfilelocation}${vtfile}"
  424.  if [ ! -f "$fullvtfile" ]
  425.  then
  426.     if [ -f "${fullvtfile}.Z" ]
  427.     then
  428.        fullvtfile="${fullvtfile}.Z"       
  429.     else
  430.        if [ -f "${fullvtfile}.gz" ]
  431.        then
  432.           fullvtfile="${fullvtfile}.gz"
  433.        else          
  434.           echo "Cannot find the FrontPage Extensions tar file in ${vtfilelocation}." 
  435.           $echo "Which directory is the file located in (X to cancel)?  ${nnl}" 
  436.           read vtfilelocation
  437.           if [ "$vtfilelocation" = "X" ] || [ "$vtfilelocation" = "x" ]
  438.           then
  439.              return 1
  440.           else
  441.              
  442.              vtfilelocation=`echo $vtfilelocation | sed -e 's/\/$//'`
  443.  
  444.              if [ ! -d "$vtfilelocation" ]
  445.              then
  446.                  vtfilelocation=`dirname $vtfilelocation`
  447.              fi
  448.  
  449.              getextfilename $vtfilelocation/ $vtfile
  450.           fi  
  451.        fi
  452.     fi
  453.  fi
  454.  
  455.  
  456. }
  457.  
  458. currentversionlink()
  459. {
  460.  #
  461.  # Make sure that untarring preserved all permissions, including SUID of 
  462.  # Apache stubs.
  463.  #
  464.  retval=0
  465.  
  466.  rm -f $installdir'currentversion'
  467.  ln -s $installdir'version'$VERSION $installdir'currentversion'
  468.  
  469.  
  470.  return $retval
  471. }
  472.  
  473. upgradeexistingservers()
  474. {
  475.  retval=0
  476.  
  477.  echo "Checking for existing web servers to upgrade..." 
  478.  
  479.  upgrade="none"
  480.  for file in ${installdir}*.cnf
  481.  do
  482.     if [ "$file" = "${installdir}*.cnf" ]
  483.     then
  484.         echo "No existing web servers found to upgrade." 
  485.         return $retval
  486.     fi
  487.  
  488.     cat <<EOF
  489.  
  490. Existing web servers were found.
  491. You can upgrade them later by re-running fp_install.sh and
  492. answering yes to the following question.
  493.  
  494. EOF
  495.     myprompt 'yYnN' "Would you like to upgrade them now (y/n)" "Y"
  496.  
  497.     if [ $answer = n ] || [ $answer = N ]
  498.     then
  499.         upgrade="no"
  500.         echo "For details on how to upgrade servers manually, please see" 
  501.         echo "the Server Extension Resource Kit (SERK), located in"
  502.         echo "/usr/local/frontpage/version3.0/serk"
  503.         echo
  504.         return $retval
  505.     else
  506.         upgrade="yes"
  507.  
  508.         cat <<EOF
  509.         
  510. The file ${installdir}currentversion/upgrade_results.txt will
  511. contain Success/Fail status for the upgrades.  When the upgrade is
  512. complete you should examine this file to make sure that all of the
  513. upgrades completed successfully.
  514.  
  515. EOF
  516.         $echo "Hit enter to continue${nnl}" 
  517.         read continue
  518.         echo
  519.  
  520.         echo "All existing servers will now be upgraded:" 
  521.         echo " " 
  522.     fi
  523.     break
  524.  done
  525.  
  526.  createdate=`date`
  527.  cat >${installdir}currentversion/upgrade_results.txt <<EOF 
  528. #
  529. # Server Upgrade Results
  530. #
  531. # Automatically generated by fp_install.sh on $createdate
  532. #
  533. EOF
  534.  
  535.  for weconfigfile in ${installdir}*.cnf
  536.  do
  537.     echo 
  538.     echo "Upgrading using configuration file:  "$weconfigfile 
  539.     if verifywebserver $weconfigfile
  540.     then
  541.         if upgradeserver $weconfigfile
  542.         then
  543.             echo "Upgrade Successful  $weconfigfile" >> ${installdir}currentversion/upgrade_results.txt
  544.         else
  545.             echo "Upgrade Failed      $weconfigfile" >> ${installdir}currentversion/upgrade_results.txt
  546.             echo "ERROR:  Server upgrade failed!"
  547.             echo "Continuing with next server." 
  548.             $echo "Hit enter to continue${nnl}" 
  549.             read continue
  550.         fi
  551.     else
  552.         echo "Cancelling upgrade..."
  553.         echo "Upgrade Failed      $weconfigfile" >> ${installdir}currentversion/upgrade_results.txt
  554.     fi
  555.  done
  556.  
  557.  weconfigfile=""
  558.  
  559.  return $retval
  560. }
  561.  
  562. verifywebserver()
  563. {
  564.  weconfigfile="$1"
  565.  
  566.  conf=`basename $weconfigfile`
  567.   port=`echo  $conf | sed -e '
  568.     s/:/:/
  569.     tmulti
  570.     s/.cnf$//
  571.     s/.*[^0-9]//
  572.     q
  573.     :multi
  574.     s/.cnf$//'`
  575.  
  576.  echo "Verifying web server configuration..."
  577.  
  578.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  579.              s/serverconfig://g
  580.              s/fakeconf.*\///'`
  581.  if [ ! -f "$configfile" ]
  582.  then
  583.      echo "$configfile does not exist."
  584.      return 1
  585.  fi
  586.   
  587.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  588.  configfiledir=`dirname $configfile`"/"
  589.  
  590.  if [ $servertype = "cern" ]
  591.  then
  592.      echo "This version of fp_install.sh does not suppport cern servers."
  593.      echo "For details on how to install or upgrade servers manually, please see" 
  594.      echo "the Server Extension Resource Kit (SERK), located in"
  595.      echo "/usr/local/frontpage/version3.0/serk"
  596.      return 1
  597.  fi
  598.  
  599.  getdocroot $weconfigfile ||
  600.  {
  601.     echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  602.     return 1
  603.  } 
  604.  
  605.  case $servertype in 
  606.       *pache*) getHttpDirective $configfile AccessConfig $port
  607.                if [ "$param" != "" ]
  608.                then
  609.                    file=`basename $param`
  610.                    accessconffile="${configfiledir}${file}"
  611.                else
  612.                    accessconffile="${configfiledir}access.conf"
  613.                fi
  614.  
  615.                if [ ! -f "$accessconffile" ]
  616.                then
  617.                    echo "$accessconffile does not exist."
  618.                    return 1
  619.                fi
  620.                ;;
  621.          ncsa) getHttpDirective $configfile AccessConfig $port
  622.                if [ "$param" != "" ]
  623.                then
  624.                    file=`basename $param`
  625.                    accessconffile="${configfiledir}${file}"
  626.                else
  627.                    accessconffile="${configfiledir}access.conf"
  628.                fi
  629.  
  630.                if [ ! -f "$accessconffile" ]
  631.                then
  632.                    echo "$accessconffile does not exist."
  633.                    return 1
  634.                fi
  635.                ;;
  636.  esac
  637.  
  638.  servicesfile=${docroot}"/_vti_pvt/services.cnf"
  639.  
  640.  if [ ! -f "$servicesfile" ]
  641.  then
  642.      echo "There are no services to upgrade for this web."
  643.      return 1
  644.  fi
  645.  
  646.  return 0
  647. }
  648.  
  649. chownexistingservers()
  650. {
  651.  retval=0
  652.  
  653.  if [ "$upgrade" = "yes" ]
  654.  then
  655.      echo
  656.      echo "Preparing to chown webs..." 
  657.      cat <<EOF
  658.  
  659. Your webs have been upgraded to use the new FrontPage Server Extensions.  The
  660. next step is to chown the web in order to guarantee that the extensions will
  661. work properly.  At this point you have two options:
  662.  
  663.    1. This script will prompt you interactively for an owner and group of
  664.       each web and then perform the chown.  If you do not have a lot of 
  665.       webs you might want to choose this option.
  666.  
  667.    2. This script will generate a script, which you can edit to fill in the
  668.       owner and group for each web, to run at a later date.  If you have a
  669.       large number of webs you might want to choose this option.
  670.  
  671. EOF
  672.  
  673.      echo "Would you like to be prompted interactively for"
  674.      myprompt 'yYnN' "each webs owner/group (y/n)" "Y"
  675.      if [ $answer = y ] || [ $answer = Y ]
  676.      then
  677.         chownwebs 
  678.      else
  679.         generatechownscript $file  ||
  680.         (
  681.             echo "ERROR:  Server chown failed!  Continuing with next server." 
  682.             $echo "Hit enter to continue${nnl}" 
  683.             read continue
  684.         )
  685.  
  686.      fi
  687.      return $retval
  688.  fi
  689. }
  690.  
  691. chownwebs()
  692. {
  693.  retval=0
  694.  
  695.  for weconfigfile in ${installdir}*.cnf
  696.  do
  697.      if grep Failed ${installdir}currentversion/upgrade_results.txt | grep ${weconfigfile} > /dev/null
  698.      then
  699.          echo
  700.          echo "Upgrade of ${weconfigfile} failed."
  701.          echo "See ${installdir}currentversion/upgrade_results.txt" 
  702.          echo "Skipping chown..."
  703.      else
  704.          chownWeb $weconfigfile
  705.      fi
  706.  done
  707.  
  708.  weconfigfile=""
  709.  
  710.  return $retval
  711. }
  712.  
  713. chownWeb()
  714. {
  715.  weconfigfile=$1
  716.  
  717.  echo 
  718.  conf=`basename $weconfigfile`
  719.  webport=`echo  $conf | sed -e '
  720.      s/:/:/
  721.      tmulti
  722.      s/.cnf$//
  723.      s/.*[^0-9]//
  724.      q
  725.      :multi
  726.      s/.cnf$//'`
  727.  
  728.  port=$webport
  729.  
  730.  echo "Processing webs in port $webport..."
  731.  echo
  732.  
  733.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  734.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  735.              s/serverconfig://g
  736.              s/fakeconf.*\///'`
  737.  configfiledir=`dirname $configfile`"/"
  738.  
  739.  getdocroot $weconfigfile ||
  740.  {
  741.     echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  742.     return 1
  743.  } 
  744.  
  745.  servicesfile=${docroot}"/_vti_pvt/services.cnf"
  746.  
  747.  exec 4<&0
  748.  exec <$servicesfile
  749.  n=0
  750.  while read service
  751.  do 
  752.     echo
  753.     if [ $service = "/" ]
  754.     then
  755.        webname=""
  756.        webtext="root web"
  757.        web=""
  758.     else
  759.        webname="$service"
  760.        webtext="$service"
  761.        web="-w $webname"
  762.     fi
  763.     exec 5<&0
  764.     exec 0<&4
  765.  
  766.     getdocroot $weconfigfile ||
  767.     {
  768.         echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  769.         return 1
  770.     } 
  771.  
  772.     case $service in
  773.        /~*)  owner=`echo $service | sed -e 's/\///'`
  774.  
  775.              webowner=`echo $service | sed -e 's/\/~//'`
  776.              homedir=`finger $webowner |  $awk ' { if (NR==2) print $2}'`
  777.              if [ -d "${homedir}/${userdir}" ]
  778.              then
  779.                  echo "Web ${webtext} on port ${webport} will be owned by ${webowner}"
  780.                  defwebgroup=`$lsg ${homedir}/${userdir} | $awk ' { print $4}'`
  781.                  exists=0
  782.              else
  783.                  exists="${homedir}/${userdir}"
  784.              fi
  785.              ;;
  786.          *)  if [ -d "${docroot}/${service}" ]
  787.              then
  788.                  defwebowner=`$lsg ${docroot}${service} | $awk ' { print $3}'`
  789.                  defwebgroup=`$lsg ${docroot}${service} | $awk ' { print $4}'`
  790.  
  791.                  webowner=""
  792.                  until [ "$webowner" != "" ]
  793.                  do
  794.                      $echo "Who should own web ${webtext} on port ${webport} [${defwebowner}]:  ${nnl}"
  795.                      read webowner
  796.                      if [ "$webowner" = "" ]
  797.                      then
  798.                          webowner=$defwebowner
  799.                      fi
  800.                  done
  801.  
  802.                  exists=0
  803.              else
  804.                  exists="${docroot}/${service}"
  805.              fi
  806.         
  807.              ;;
  808.     esac
  809.  
  810.     if [ "$exists" = "0" ]
  811.     then
  812.         webgroup=""
  813.         until [ "$webgroup" != "" ]
  814.         do
  815.             $echo "What should the group for web ${webtext} on port ${webport} be [${defwebgroup}]:  ${nnl}"
  816.             read webgroup
  817.             if [ "$webgroup" = "" ]
  818.             then
  819.                 webgroup=$defwebgroup
  820.             fi
  821.         done
  822.  
  823.         /usr/local/frontpage/version${VERSION}/bin/fpsrvadm.exe -o chown -p $webport $web -xUser $webowner -xGroup $webgroup ||
  824.         {
  825.             echo 
  826.             echo "ERROR:  Unable to chown web ${webtext} in port ${webport}"
  827.             $echo "Hit enter to continue${nnl}" 
  828.             read continue
  829.         }
  830.     else
  831.         echo "ERROR:  web $service - $exists does not exist!  Skipping to next web."  
  832.     fi
  833.         exec 0<&5
  834.  done
  835.  exec <&4
  836.  
  837. }
  838.  
  839. generatechownscript()
  840. {
  841.  retval=0
  842.  scriptout="/usr/local/frontpage/version${VERSION}/fp_chown.sh"
  843.  createdate=`date`
  844.  
  845.  cat <<EOF
  846.  
  847. A script will be generated in ${scriptout} 
  848. which you can edit to chown your webs at a future date.  You will 
  849. need to edit the script and set the owner and group for each web 
  850. before running the script.
  851.  
  852. EOF
  853.  
  854.  cat >$scriptout <<EOF 
  855. #! /bin/sh
  856. #
  857. #
  858. # Copyright 1996 Microsoft Corporation -- All Rights Reserved.
  859. #
  860. #          Automatically generated by fp_install.sh
  861. #
  862. # Automatically generated by fp_install.sh on $createdate
  863. #
  864. # You will need to edit this script before running it.  Change each 
  865. # <OWNER> and <GROUP> to reflect the ownership/group that you want 
  866. # set for the web.
  867. #
  868. # Example:  80 /testweb webowner webgroup
  869. #
  870.  
  871. VERSION="3.0"
  872.  
  873. chown_web()
  874. {
  875.  port=\$1
  876.  webname=\$2
  877.  webowner=\$3
  878.  webgroup=\$4
  879.  
  880.  if [ "\$webowner" = "<OWNER>" ] || [ "\$webgroup" = "<GROUP>" ]
  881.  then
  882.      echo "WARNING:  Owner/Group not specified for web \$webname on \$port."
  883.      echo "Skipping to next web..."
  884.  else
  885.      if [ "\$webname" != "/" ]
  886.      then
  887.         webname=\`echo \$webname | sed -e 's%^/%%g'\`
  888.         webtext="\$webname"
  889.         web="-w \$webname"
  890.      else
  891.         webtext="root web"
  892.         web=""
  893.      fi
  894.      echo
  895.      echo "Chowning web \${webtext} in port \${port} to owner \${webowner} group \${webgroup}"
  896.      /usr/local/frontpage/version3.0/bin/fpsrvadm.exe -o chown -p \$port  \$web  -xUser \$webowner -xGroup \$webgroup
  897.  fi
  898. }
  899.  
  900. while read port webname webowner webgroup
  901. do
  902.     chown_web \$port \$webname \$webowner \$webgroup
  903. done <<ENDCHOWN
  904. EOF
  905.  
  906.  for weconfigfile in ${installdir}*.cnf
  907.  do
  908.      if grep Failed ${installdir}currentversion/upgrade_results.txt | grep ${weconfigfile} > /dev/null
  909.      then 
  910.          echo
  911.          echo "Upgrade of ${weconfigfile} failed."
  912.          echo "See ${installdir}currentversion/upgrade_results.txt" 
  913.          echo "Skipping chown..."
  914.      else
  915.          addChownWeb $weconfigfile
  916.      fi
  917.  done
  918.  
  919.  echo "ENDCHOWN" >>$scriptout
  920.  
  921.  chmod 764 $scriptout
  922.  
  923.  weconfigfile=""
  924.  return $retval
  925. }
  926.  
  927. addChownWeb()
  928. {
  929.  
  930.  weconfigfile=$1
  931.  
  932.  echo 
  933.  echo "Processing  $weconfigfile"
  934.  conf=`basename $weconfigfile`
  935.  webport=`echo  $conf | sed -e '
  936.     s/:/:/
  937.     tmulti
  938.     s/.cnf$//
  939.     s/.*[^0-9]//
  940.     q
  941.     :multi
  942.     s/.cnf$//'`
  943.  
  944.  port=$webport
  945.  
  946.  echo "Adding webs in port ${webport} to chown script..."
  947.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  948.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  949.              s/serverconfig://g
  950.              s/fakeconf.*\///'`
  951.  configfiledir=`dirname $configfile`"/"
  952.  getdocroot $weconfigfile ||
  953.  {
  954.      echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  955.      return 1
  956.  } 
  957.  
  958.  servicesfile="${docroot}/_vti_pvt/services.cnf"
  959.  if [ -r $servicesfile ]
  960.  then
  961.      exec 4<&0
  962.      exec <$servicesfile
  963.      n=0
  964.  
  965.      while read service
  966.      do 
  967.         if [ $service = "/" ]
  968.         then
  969.             webtext="root web"
  970.         else
  971.             webtext="$service"
  972.         fi
  973.         
  974.         case $service in
  975.            /~*)  owner=`echo $service | sed -e 's/\///'`
  976.  
  977.                  webowner=`echo $service | sed -e 's/\/~//'`
  978.                  homedir=`finger $webowner |  $awk ' { if (NR==2) print $2}'`
  979.                  if [ -d "${homedir}/${userdir}" ]
  980.                  then
  981.                      webgroup=`$lsg ${homedir}/${userdir} | $awk ' { print $4}'`
  982.                      exists="0"
  983.  
  984.                  else
  985.                      exists="${homedir}/${userdir}"
  986.                  fi
  987.                  ;;
  988.              *)  if [ -d "${docroot}/${service}" ]
  989.                  then
  990.                      webowner=`$lsg ${docroot}${service} | $awk ' { print $3}'`
  991.                      webgroup=`$lsg ${docroot}${service} | $awk ' { print $4}'`
  992.                      exists="0"
  993.                  else
  994.                      exists="${docroot}/${service}"
  995.                  fi
  996.                  ;;
  997.         esac
  998.  
  999.  
  1000.      if [ "$exists" = "0" ]
  1001.      then
  1002.         echo "web ${webtext}"
  1003.         echo "$webport $service $webowner $webgroup" >> $scriptout
  1004.      else
  1005.         echo "ERROR:  web ${webtext}- Path $exists does not exist!  Skipping to next web."  
  1006.      fi        
  1007.      done
  1008.      exec <&4
  1009.  else
  1010.      echo "WARNING:  Unable to read $servicesfile!" 
  1011.      echo "Skipping to next port."
  1012.  fi
  1013.  
  1014. }
  1015.  
  1016. upgradeserver()
  1017. {
  1018.  retval=0
  1019.  weconfigfile="$1"
  1020.  
  1021.  bindir=$installdir'version'$VERSION'/bin/'
  1022.  
  1023.  conf=`basename $weconfigfile`
  1024.  
  1025.  echo "Upgrading server "$port 
  1026.  
  1027.  /usr/local/frontpage/version${VERSION}/bin/fpsrvadm.exe -o upgrade -p $port
  1028.  
  1029.  return $retval
  1030. }
  1031.  
  1032. installrootweb()
  1033. {
  1034.  retval=0
  1035.  
  1036.  configfile=""
  1037.  admin=""
  1038.  port=""
  1039.  multihost=""
  1040.  webname=""
  1041.  webowner=""
  1042.  adminpwd=""
  1043.  servertype=""
  1044.  
  1045.  echo 
  1046.  echo "Note: If you have not installed the root web then you need to do it now." 
  1047.  echo 
  1048.  myprompt 'yYnN' "Do you want to install a root web (y/n)" "Y"
  1049.  if [ $answer = n ] || [ $answer = N ]
  1050.  then
  1051.      return $retval
  1052.  fi
  1053.  
  1054.  echo " " 
  1055.  echo "Installing the root web..." 
  1056.  echo " " 
  1057.  
  1058.  webname="/"
  1059.  
  1060.  configfile=""
  1061.  while ( [ "$configfile" = "" ] || [ ! -f $configfile ] )
  1062.  do
  1063.      $echo "Server config filename:  ${nnl}" 
  1064.      read configfile
  1065.  done
  1066.  
  1067.  admin=""
  1068.  until [ "$admin" != "" ]
  1069.  do
  1070.      $echo "FrontPage Administrator's user name:  ${nnl}" 
  1071.      read admin
  1072.  done
  1073.  
  1074.  getpassword "FrontPage Administrator's password"
  1075.  adminpwd=$PASSWORD
  1076.  
  1077.  getparam Port $configfile
  1078.  port=$param
  1079.  
  1080.  until [ "$port" != "" ]
  1081.  do
  1082.     $echo "Enter the new servers port number:  ${nnl}" 
  1083.     read port
  1084.  done
  1085.  
  1086.  getparam User $configfile
  1087.  webowner=$param
  1088.  
  1089.  weconfigfile="${installdir}we${port}.cnf"
  1090.  
  1091.  defwebowner=`$lsg ${docroot}${service} | $awk ' { print $3}'`
  1092.  
  1093.  webowner=""
  1094.  until [ "$webowner" != "" ]
  1095.  do
  1096.      $echo "User name of the owner of this new web:[$defwebowner]  ${nnl}"
  1097.      read webowner
  1098.      if [ "$webowner" = "" ]
  1099.      then
  1100.          webowner=$defwebowner
  1101.      fi
  1102.  done
  1103.  
  1104.  getparam Group $configfile
  1105.  defgroup=$param
  1106.  webgroup=""
  1107.  until [ "$webgroup" != "" ]
  1108.  do
  1109.      echo 
  1110.      $echo "Group of this new web:[$defgroup]  ${nnl}" 
  1111.      read webgroup
  1112.      if [ "$webgroup" = "" ]
  1113.      then
  1114.         webgroup=$defgroup
  1115.      fi
  1116.  done
  1117.  
  1118.  until [ "$servertype" != "" ]
  1119.  do
  1120.      echo 
  1121.      echo "    1.  ncsa" 
  1122.      echo "    2.  apache" 
  1123.      echo "    3.  apache-fp"
  1124.      echo "    4.  apache-wpp" 
  1125.      echo "    5.  cern" 
  1126.      echo "    6.  netscape-communication" 
  1127.      echo "    7.  netscape-commerce" 
  1128.      echo "    8.  netscape-fasttrack" 
  1129.      echo "    9.  netscape-enterprise" 
  1130.      $echo "What type of Server is this:  ${nnl}" 
  1131.      read servertypenum
  1132.      echo 
  1133.  
  1134.      case $servertypenum in
  1135.           "1") servertype="ncsa" ;;
  1136.           "2") servertype="apache" ;;
  1137.           "3") servertype="apache-fp" ;;
  1138.           "4") servertype="apache-wpp" ;;
  1139.           "5") echo "This version of fp_install.sh does not suppport cern servers."
  1140.                echo "For details on how to install or upgrade servers manually, please see" 
  1141.                echo "the Server Extension Resource Kit (SERK), located in"
  1142.                echo "/usr/local/frontpage/version3.0/serk" ;;
  1143.           "6") servertype="netscape-communication" ;;
  1144.           "7") servertype="netscape-commerce" ;;
  1145.           "8") servertype="netscape-fasttrack" ;;
  1146.           "9") servertype="netscape-enterprise" ;;
  1147.             *) echo "Invalid option!  Please try again."   ;;
  1148.      esac 
  1149.  done
  1150.  
  1151.  multihost="."
  1152.  if [ "$configfile" = "" ]
  1153.  then
  1154.      configfile="."
  1155.  fi
  1156.  
  1157.  PORT=$port
  1158.  
  1159.  echo "Installing root web into port $port..." 
  1160.  echo 
  1161.  installserver $port $multihost $webname $webowner $webgroup $admin $adminpwd $configfile $servertype ||
  1162.  {
  1163.      echo "ERROR:  $webname installation failed." 
  1164.      $echo "Hit enter to continue${nnl}" 
  1165.      read continue
  1166.      return $retval
  1167.  }
  1168.  
  1169.  isItApacheFP
  1170.  handlelanguage
  1171.  
  1172.  return $retval
  1173. }
  1174.  
  1175. isItApacheFP()
  1176. {
  1177.  retval=0
  1178.  
  1179.  if [ "$servertype" = "apache-fp" ]
  1180.  then
  1181.      fpexe=$installdir'version'$VERSION'/apache-fp/_vti_bin/fpexe'
  1182.  
  1183.      echo 
  1184.      echo "Chowning $fpexe to root..." 
  1185.      chown root $fpexe ||
  1186.        (
  1187.         echo "ERROR:  Unable to chown $fpexe to root" 
  1188.         retval=1
  1189.        )
  1190.  
  1191.      echo "Setting $fpexe to SUID..." 
  1192.      chmod u+s $fpexe ||
  1193.        (
  1194.         echo "ERROR:  Unable to set SUID for "$fpexe 
  1195.         retval=1
  1196.        ) 
  1197.  fi
  1198.  
  1199.  return $retval
  1200.  
  1201. }
  1202.  
  1203. handlelanguage()
  1204. {
  1205.  retval=0
  1206.  
  1207.  until [ "$charencoding" != "" ]
  1208.  do
  1209.      echo 
  1210.      echo "    1.  LATIN1 (ISO 8859-1)" 
  1211.      echo "    2.  LATIN2 (ISO 8859-2)" 
  1212.      echo "    3.  EUCJP  (Japanese EUC)" 
  1213.      echo "    4.  EUCKR  (Korean EUC)" 
  1214.      $echo "Which local character encoding do your system support: [1]  ${nnl}" 
  1215.      read charencodingnum
  1216.      echo
  1217.  
  1218.      case $charencodingnum in
  1219.          "") charencoding="latin1" ;;
  1220.          "1") charencoding="latin1" ;;
  1221.          "2") charencoding="latin2" ;;
  1222.          "3") charencoding="eucjp" ;;
  1223.          "4") charencoding="euckr" ;;
  1224.            *) echo "Invalid option!  Please try again."  ;;
  1225.      esac
  1226.  done
  1227.  
  1228.  until [ "$lang" != "" ]
  1229.  do
  1230.      echo 
  1231.      echo "    1.  English" 
  1232.      echo "    2.  French" 
  1233.      echo "    3.  German" 
  1234.      echo "    4.  Italian" 
  1235.      echo "    5.  Japanese" 
  1236.      echo "    6.  Spanish" 
  1237.      $echo "What should the default language be: [1] ${nnl}" 
  1238.      read langnum
  1239.      echo 
  1240.  
  1241.      case $langnum in
  1242.          "") lang="en" ;;
  1243.          "1") lang="en" ;;
  1244.          "2") lang="fr" ;;
  1245.          "3") lang="de" ;;
  1246.          "4") lang="it" ;;
  1247.          "5") lang="ja" ;;
  1248.          "6") lang="es" ;;
  1249.            *) echo "Invalid option!  Please try again."  ;;
  1250.      esac
  1251.  done
  1252.  
  1253.  conffile=$installdir'version'$VERSION'/frontpage.cnf'
  1254.  echo "Setting "$conffile" to:" 
  1255.  echo 
  1256.  echo "defaultLanguage:${lang}"
  1257.  echo "localCharEncoding:${charencoding}"
  1258.  echo 
  1259.  echo "Moving ${conffile} to ${conffile}.orig"
  1260.  echo
  1261.  mv $conffile ${conffile}.orig ||
  1262.  {
  1263.     echo "ERROR:  Unable to backup $conffile to ${conffile}.orig!"
  1264.     $echo "Hit enter to continue${nnl}" 
  1265.     read continue
  1266.     return 1
  1267.  }
  1268.  
  1269.  echo "Creating and modifying new ${conffile}..."
  1270.  echo
  1271.  sed -e "s/defaultLanguage:.*/defaultLanguage:${lang}/g
  1272.          s/localCharEncoding:.*/localCharEncoding:${charencoding}/g" \
  1273.       ${conffile}.orig > $conffile ||
  1274.  {
  1275.     echo "ERROR:  Unable to create new $conffile!"
  1276.     echo "If the file has been corrupted you should be able to replace it with"
  1277.     echo "the backup file (${conffile}.orig)"
  1278.     $echo "Hit enter to continue${nnl}" 
  1279.     read continue
  1280.     return 1 
  1281.  }                          
  1282.  
  1283.  return $retval
  1284. }
  1285.  
  1286. installvirtualwebs()
  1287. {
  1288.  retval=0
  1289.  
  1290.  echo
  1291.  echo "Installing Virtual Webs.." 
  1292.  echo 
  1293.  myprompt 'yYnN' "Do you want to install Virtual Webs (y/n)" "Y"
  1294.  if [ $answer = n ] || [ $answer = N ]
  1295.  then
  1296.      return $retval
  1297.  fi
  1298.  
  1299.  defaultconfigfile=$configfile
  1300.  configfile=""
  1301.  while ( [ "$configfile" = "" ] || [ ! -f $configfile ] )
  1302.  do
  1303.      $echo "Server config filename [${defaultconfigfile}]:  ${nnl}" 
  1304.      read configfile
  1305.      if [ "$configfile" = "" ]
  1306.      then
  1307.          configfile=$defaultconfigfile
  1308.      fi
  1309.  done
  1310.  
  1311.  getparam Port $configfile
  1312.  port=$param
  1313.  getparam User $configfile
  1314.  webowner=$param
  1315.  
  1316.  case $configfile in 
  1317.       *magnus*) echo
  1318.                 echo "Looking for Netscape virtuals..."
  1319.                 n=0              
  1320.                 resourcefile=`echo $configfile | sed -e 's/magnus\.conf/obj.conf/'`  
  1321.                 urlhosts=`grep -i \urlhost $resourcefile`
  1322.                 if [ "$urlhosts" ]
  1323.                 then
  1324.                     novirtuals=0
  1325.                 else
  1326.                     novirtuals=1
  1327.                 fi
  1328.  
  1329.                 while [ "$urlhosts" ]
  1330.                 do       
  1331.                     urlhost=`echo $urlhosts | sed -e '
  1332.                            s/>.*/>/'`
  1333.                     virtweb=`echo $urlhost | sed -e '
  1334.                             s/\"//g
  1335.                             s/ *<.*= *//
  1336.                             s/ *> *//'` 
  1337.                     n=`expr $n + 1`                
  1338.                     eval virtwebs$n="$virtweb"
  1339.                     urlhost=`echo $urlhost | sed -e '
  1340.                            s/\./\\\./g
  1341.                            s/\"/\\\"/g'`
  1342.                     urlhosts=`echo $urlhosts | sed -e "s/$urlhost *//"`
  1343.                 done
  1344.                
  1345.                 if [ $novirtuals = 1 ]
  1346.                 then
  1347.                     echo "ERROR:  There are no valid virtual webs defined." 
  1348.                     $echo "Hit enter to continue${nnl}" 
  1349.                     read continue
  1350.                     return 1
  1351.                 fi
  1352.                 ;;
  1353.              *) #exec 4<&0
  1354.                 #exec <$configfile
  1355.                 #n=0
  1356.                 virtnames=`grep -i "^[^#]* *< *VirtualHost" $configfile | $awk '{print $2}' | sed -e 's/>//g'`
  1357.  
  1358.                 n=0
  1359.                 for word in $virtnames 
  1360.                 do 
  1361.                     n=`expr $n + 1` 
  1362.                     eval virtwebs$n="$word" 
  1363.                 done
  1364.                 ;;
  1365.  esac
  1366.  
  1367.  while echo
  1368.        n=1
  1369.        val=`eval echo $"virtwebs$n"`
  1370.        while [ "$val" != "" ]
  1371.        do
  1372.           echo "  $n) $val" 
  1373.           n=`expr $n + 1`
  1374.           val=`eval echo $"virtwebs$n"`
  1375.        done
  1376.  
  1377.        echo 
  1378.        $echo "Select the virtual web to install (CTRL-D if no more webs): ${nnl}" 
  1379.        read virtwebno
  1380.  do
  1381.     getparam Port $configfile
  1382.     port=$param
  1383.     until [ "$port" != "" ]
  1384.     do
  1385.         $echo "Enter the new servers port number:  ${nnl}" 
  1386.         read port
  1387.     done
  1388.  
  1389.     port="`eval echo $"virtwebs$virtwebno"`:$port"
  1390.  
  1391.     getHttpVirtualDirective $configfile $port User
  1392.     defwebowner=$param
  1393.  
  1394.     webowner=""
  1395.     until [ "$webowner" != "" ]
  1396.     do
  1397.         $echo "User name of the owner of this new web:[$defwebowner]  ${nnl}"
  1398.         read webowner
  1399.         if [ "$webowner" = "" ]
  1400.         then
  1401.             webowner=$defwebowner
  1402.         fi
  1403.     done
  1404.  
  1405.     getHttpVirtualDirective $configfile $port Group
  1406.     defwebgroup=$param
  1407.  
  1408.     webgroup=""
  1409.     until [ "$webgroup" != "" ]
  1410.     do
  1411.         echo 
  1412.         $echo "Group of this new web:[$defgroup]  ${nnl}" 
  1413.         read webgroup
  1414.         if [ "$webgroup" = "" ]
  1415.         then
  1416.             webgroup=$defgroup
  1417.         fi
  1418.     done
  1419.      
  1420.     webname="/"
  1421.  
  1422.     $echo "FrontPage Administrator's user name:  ${nnl}" 
  1423.     read admin
  1424.  
  1425.     getpassword "FrontPage Administrator's password"
  1426.     adminpwd=$PASSWORD
  1427.  
  1428.     until [ "$servertype" != "" ]
  1429.     do
  1430.      echo 
  1431.      echo "    1.  ncsa" 
  1432.      echo "    2.  apache" 
  1433.      echo "    3.  apache-fp"
  1434.      echo "    4.  apache-wpp" 
  1435.      echo "    5.  cern" 
  1436.      echo "    6.  netscape-communication" 
  1437.      echo "    7.  netscape-commerce" 
  1438.      echo "    8.  netscape-fasttrack" 
  1439.      echo "    9.  netscape-enterprise" 
  1440.      $echo "What type of Server is this:  ${nnl}" 
  1441.      read servertypenum
  1442.      echo 
  1443.  
  1444.      case $servertypenum in
  1445.           "1") servertype="ncsa" ;;
  1446.           "2") servertype="apache" ;;
  1447.           "3") servertype="apache-fp" ;;
  1448.           "4") servertype="apache-wpp" ;;
  1449.           "5") echo "This version of fp_install.sh does not suppport cern servers."
  1450.                echo "For details on how to install or upgrade servers manually, please see" 
  1451.                echo "the Server Extension Resource Kit (SERK), located in"
  1452.                echo "/usr/local/frontpage/version3.0/serk" ;;
  1453.           "6") servertype="netscape-communication" ;;
  1454.           "7") servertype="netscape-commerce" ;;
  1455.           "8") servertype="netscape-fasttrack" ;;
  1456.           "9") servertype="netscape-enterprise" ;;
  1457.             *) echo "Invalid option!  Please try again."   ;;
  1458.        esac 
  1459.     done
  1460.  
  1461.     multihost="`eval echo $"virtwebs$virtwebno"`"
  1462.     if [ "$configfile" = "" ]
  1463.     then
  1464.        configfile="."
  1465.     fi
  1466.     if [ "$servertype" = "" ]
  1467.     then
  1468.        servertype="."
  1469.     fi
  1470.  
  1471.  
  1472.     PORT=$port
  1473.     echo "Installing virtual root web into port $port..." 
  1474.     echo 
  1475.     installserver $port $multihost $webname $webowner $webgroup $admin $adminpwd $configfile $servertype ||
  1476.     {
  1477.         echo "ERROR:  $webname installation failed." 
  1478.         $echo "Hit enter to continue${nnl}" 
  1479.         read continue
  1480.         return $retval
  1481.     }
  1482.  
  1483.     isItApacheFP
  1484.     handlelanguage
  1485.     
  1486.     weconfigfile=""
  1487.  
  1488.     installnewsubwebs $PORT || error     # Install new servers
  1489.     echo
  1490.  done
  1491.  
  1492.  return $retval
  1493.  
  1494. }
  1495.  
  1496. installnewsubwebs()
  1497. {
  1498.  port=$1
  1499.  
  1500.  retval=0
  1501.  
  1502.  echo 
  1503.  myprompt 'yYnN' "Install new sub/per-user webs now (y/n)" "Y"
  1504.  if [ $answer = n ] || [ $answer = N ]
  1505.  then
  1506.      echo "For details on how to upgrade servers manually, please see" 
  1507.      echo "the Server Extension Resource Kit (SERK), located in"
  1508.      echo "/usr/local/frontpage/version3.0/serk"
  1509.      echo
  1510.      return $retval
  1511.  fi
  1512.  echo 
  1513.  
  1514.  if [ "$weconfigfile" = "" ]
  1515.  then
  1516.      until [ "$weconfigfile" != "" ] && [ -f $weconfigfile ]
  1517.      do
  1518.          port=""
  1519.          if [ "$port" = "" ]
  1520.          then
  1521.              cat <<EOF
  1522.  
  1523. You need to specify which server to install the subweb into.
  1524. Examples:
  1525.           80
  1526.           www.virtual.web:80
  1527.  
  1528.           where 80 is the port the server is running on.
  1529.  
  1530. EOF
  1531.              $echo "Which server would you like to install the subweb into:  ${nnl}" 
  1532.              read port
  1533.          fi
  1534.          echo 
  1535.          case $port in 
  1536.               *:*) weconfigfile="${installdir}${port}.cnf" ;;
  1537.                 *) weconfigfile="${installdir}we${port}.cnf" ;;
  1538.          esac
  1539.      done
  1540.  fi
  1541.  
  1542.  echo
  1543.  echo "Using FrontPage Configuration File:  ${weconfigfile}"
  1544.  echo
  1545.  
  1546.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  1547.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  1548.              s/serverconfig://g
  1549.              s/fakeconf.*\///'`
  1550.  configfiledir=`dirname $configfile`"/"
  1551.  
  1552.  getdocroot $weconfigfile ||
  1553.  {
  1554.     echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  1555.     return 1
  1556.  } 
  1557.  
  1558.  services=${docroot}"/_vti_pvt/services.cnf"
  1559.  
  1560.  if [ ! -f $services ]
  1561.  then
  1562.     echo
  1563.     echo "ERROR:  The root web must be installed before sub/per-user webs!"
  1564.     echo "Document Root:  ${docroot}"
  1565.     $echo "Hit enter to continue${nnl}" 
  1566.     read continue
  1567.     echo
  1568.     return $retval
  1569.  fi
  1570.  
  1571.  echo 
  1572.  while $echo "Enter the web name (CTRL-D if no more webs): ${nnl}" 
  1573.        read webname    
  1574.  do
  1575.     $echo "FrontPage Administrator's user name:  ${nnl}" 
  1576.     read admin
  1577.  
  1578.     getpassword "FrontPage Administrator's password"
  1579.     adminpwd=$PASSWORD
  1580.  
  1581.     case "$webname" in
  1582.         ~*) PERUSER=1
  1583.             echo 
  1584.             echo "Web $webname is a per-user web" 
  1585.             echo
  1586.             webowner=$webname
  1587.             ;;
  1588.          *) PERUSER=0
  1589.             echo 
  1590.             echo "Web $webname is a subweb"  
  1591.             echo
  1592.             $echo "User name of the owner of this new web:  ${nnl}"
  1593.             read webowner
  1594.             ;;
  1595.     esac
  1596.  
  1597.     getparam Group $configfile
  1598.     defgroup=$param
  1599.     webgroup=""
  1600.     until [ "$webgroup" != "" ]
  1601.     do
  1602.        echo 
  1603.        $echo "Group of this new web:[$defgroup]  ${nnl}" 
  1604.        read webgroup
  1605.        if [ "$webgroup" = "" ]
  1606.        then
  1607.            webgroup=$defgroup
  1608.        fi
  1609.     done
  1610.   
  1611.     multihost="."
  1612.  
  1613.     if [ "$configfile" = "" ]
  1614.     then
  1615.        configfile="."
  1616.     fi
  1617.  
  1618.     if [ "$servertype" = "" ]
  1619.     then
  1620.        servertype="."
  1621.     fi
  1622.  
  1623.     installserver $port $multihost $webname $webowner $webgroup $admin $adminpwd $configfile $servertype ||
  1624.     {
  1625.         echo "ERROR:  $webname installation failed." 
  1626.         $echo "Hit enter to continue${nnl}"
  1627.         retval=0 
  1628.         read continue
  1629.     }
  1630.     echo 
  1631.  done
  1632.  
  1633.  return $retval
  1634. }
  1635.  
  1636. installserver()
  1637. {
  1638.  retval=0
  1639.  
  1640.  port="$1"
  1641.  multihost="$2"
  1642.  webname="$3"
  1643.  webowner="$4"
  1644.  webgroup="$5"
  1645.  admin="$6"
  1646.  adminpwd="$7"
  1647.  configfile="$8"
  1648.  servertype="$9"
  1649.  
  1650.  echo 
  1651.  echo "installing server "$webname" on port "$port 
  1652.  
  1653.  if [ "$PERUSER" = 1 ]
  1654.  then
  1655.      user=`echo $webowner | sed -e 's/~//g'`
  1656.      echo 
  1657.      echo "Will chown per-user web to $user as part of install." 
  1658.      echo "Will chgrp per-user web to $webgroup as part of install." 
  1659.      chown="-xUser $user -xGroup $webgroup"  
  1660.  else
  1661.      if [ "$webowner" != "." ]
  1662.      then
  1663.         echo 
  1664.         echo "Will chown web to $webowner as part of install." 
  1665.         echo "Will chgrp web to $webgroup as part of install." 
  1666.         chown="-xUser $webowner -xGroup $webgroup"
  1667.      else
  1668.         chown=""
  1669.      fi
  1670.  fi
  1671.  
  1672.  if [ "$configfile" != "." ]
  1673.  then
  1674.      config="-s $configfile"
  1675.  else
  1676.      config=""
  1677.  fi
  1678.  
  1679.  if [ "$servertype" != "." ]
  1680.  then
  1681.      server="-type $servertype"
  1682.  else
  1683.      server=""
  1684.  fi
  1685.  
  1686.  if [ "$webname" != "/" ]
  1687.  then 
  1688.      web="-w $webname"
  1689.  else
  1690.      web=""
  1691.  fi
  1692.  
  1693.  if [ "$multihost" != "." ]
  1694.  then
  1695.     /usr/local/frontpage/version${VERSION}/bin/fpsrvadm.exe -o install -p $port $web $config -u $admin -pw $adminpwd $server $chown -m $multihost || retval=1
  1696.  else
  1697.     /usr/local/frontpage/version${VERSION}/bin/fpsrvadm.exe -o install -p $port $web $config -u $admin -pw $adminpwd $server $chown -m "" || retval=1
  1698.  fi
  1699.  
  1700.  return $retval
  1701.  
  1702. }
  1703.  
  1704. getdocroot()
  1705. {
  1706.  weconfigfile=$1
  1707.  
  1708.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  1709.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  1710.              s/serverconfig://g
  1711.              s/fakeconf.*\///'`
  1712.  
  1713.  echo
  1714.  echo "Getting DocumentRoot and UserDir."
  1715.  
  1716.  if [ ! -f "$configfile" ]
  1717.  then
  1718.      echo "$configfile does not exist."
  1719.      return 1
  1720.  fi
  1721.  
  1722.  configfiledir=`dirname $configfile`"/"
  1723.   
  1724.  docroot=""
  1725.  
  1726.  case $weconfigfile in
  1727.       *:*) getvirtualdocroot $weconfigfile $configfile
  1728.            ;;
  1729.         *) case $servertype in 
  1730.                 *etscape*) getnetscapedocroot $configfile
  1731.                            ;; 
  1732.                         *) getHttpDirective $configfile ResourceConfig $port
  1733.                            if [ "$param" != "" ]
  1734.                            then
  1735.                                file=`basename $param`
  1736.                                resconffile="${configfiledir}${file}"
  1737.                            else
  1738.                                resconffile="${configfiledir}srm.conf"
  1739.                            fi
  1740.  
  1741.                            if [ ! -f "$resconffile" ]
  1742.                            then
  1743.                                echo "ERROR: $resconffile does not exist!"
  1744.                                return 1
  1745.                            fi
  1746.  
  1747.                            echo "Getting DocumentRoot from $resconffile."
  1748.                            getparam DocumentRoot $resconffile
  1749.                            docroot=$param
  1750.  
  1751.                            echo "Getting UserDir from $resconffile."
  1752.                            getparam UserDir $resconffile
  1753.                            userdir=$param
  1754.                            ;; 
  1755.            esac  
  1756.            ;;
  1757.  esac
  1758.  
  1759.  if [ ! -d "$docroot" ]
  1760.  then
  1761.      echo "ERROR:  ${docroot} does not exist!"
  1762.      return 1
  1763.  fi
  1764.  
  1765.  if [ "$docroot" = "" ]
  1766.  then
  1767.      echo "ERROR:  DocumentRoot not defined!"
  1768.      return 1
  1769.  fi
  1770.  
  1771.  echo
  1772.  echo "DocumentRoot: $docroot"
  1773.  
  1774.  if [ "$userdir" = "" ]
  1775.  then
  1776.      echo "WARNING:  UserDir not defined."
  1777.  else
  1778.      echo "UserDir: $userdir"
  1779.  fi
  1780.  
  1781.  echo
  1782.  
  1783.  return 0
  1784.  
  1785. }
  1786.  
  1787. getHttpDirective()
  1788. {
  1789.  configfile=$1
  1790.  directive=$2
  1791.  port=$3
  1792.  
  1793.  case $port in
  1794.     *:*) getHttpVirtualDirective $configfile $port $directive ;;
  1795.       *) getHttpRootDirective $configfile $directive ;;
  1796.  esac
  1797.  
  1798.  if [ "$param" = "" ]
  1799.  then
  1800.      echo "Directive $directive not found."
  1801.  else 
  1802.      echo "Found Directive $directive, value $param."
  1803.  fi
  1804. }
  1805.  
  1806. getHttpRootDirective()
  1807. {
  1808.  configfile=$1
  1809.  directive=$2
  1810.  
  1811.  mc_directive=`$awk "
  1812.                BEGIN {
  1813.                    newstring = \"\";
  1814.                    oldstring = \"$directive\";
  1815.                    strlen = length(oldstring);
  1816.                    for ( i = 1; i <= strlen; ++i ) {
  1817.                        char = substr(oldstring, i, 1)
  1818.                        newstring = newstring \"[\" toupper(char) tolower(char) \"]\";
  1819.                    };
  1820.                    print newstring}"`
  1821.  
  1822.  param=`cat $configfile | $awk "
  1823.             /^[^#]* *< *[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/,/^[^#]* *< *\/[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/ { next }
  1824.             /^[^#]* *$mc_directive[ $TAB]/  { print \\\$2 }"` 
  1825.  
  1826.  return 0
  1827.  
  1828. }
  1829.  
  1830. getHttpVirtualDirective()
  1831. {
  1832.  configfile=$1
  1833.  port=$2
  1834.  directive=$3
  1835.  
  1836.  virtweb=`echo  $port | sed -e 's/:[0-9]*.$//'`
  1837.  virtweb=`basename $virtweb`
  1838.  
  1839.  mc_directive=`$awk "
  1840.                BEGIN {
  1841.                    oldstring=\"$directive\"
  1842.                    newstring = \"\";
  1843.                    strlen = length(oldstring);
  1844.                    for ( i = 1; i <= strlen; ++i ) {
  1845.                        char = substr(oldstring, i, 1)
  1846.                        newstring = newstring \"[\" toupper(char) tolower(char) \"]\";
  1847.                    };
  1848.                    print newstring }"`
  1849.  
  1850.  
  1851.  param=`cat $configfile | $awk "
  1852.                           BEGIN    { value = \"\" }
  1853.                                    { x=0 }
  1854.                               /^[^#]* *< *[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt] +$virtweb/,/^[^#]* *< *\/[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/ { x=1 }
  1855.                               /^[^#]* *$mc_directive[ $TAB]/  { if (x==1) value = \\\$2 }
  1856.                           END { print value }"`
  1857.  
  1858.  if [ "$param" = "" ]
  1859.  then
  1860.     getHttpRootDirective $configfile $directive
  1861.  fi 
  1862.  
  1863. }
  1864.  
  1865. getnetscapedocroot()
  1866. {
  1867.  configfile=$1
  1868.  
  1869.  echo "Getting DocumentRoot from ${configfiledir}obj.conf."
  1870.  
  1871.  resourcefile=`echo $configfile | sed -e 's/magnus\.conf/obj.conf/'`  
  1872.  
  1873.  echo
  1874.  echo "Getting DocumentRoot from ${resourcefile}."
  1875.  
  1876.  exec 4<&0
  1877.  exec <$resourcefile
  1878.                 
  1879.  while read line
  1880.  do 
  1881.      uc_line=`echo $line | tr [a-z] [A-Z]`
  1882.      case $uc_line in
  1883.           *DOCUMENT-ROOT*) docroot=`echo $line | sed -e '
  1884.                                     s/\"//g
  1885.                                     s/.* [Rr][Oo][Oo][Tt]= *//
  1886.                                     s/ .*//'` 
  1887.                            ;;
  1888.                  *SUBDIR*) userdir=`echo $line | sed -e '
  1889.                                     s/\"//g
  1890.                                     s/.* [Ss][Uu][Bb][Dd][Ii][Rr]= *//
  1891.                                     s/ .*//'` 
  1892.                      ;;
  1893.                 \<CLIENT*) while read line
  1894.                            do 
  1895.                                uc_line=`echo $line | tr [a-z] [A-Z]`
  1896.                                case $uc_line in
  1897.                                    \</CLIENT\>) break 
  1898.                                                 ;;
  1899.                                esac
  1900.                            done 
  1901.                            ;;
  1902.      esac
  1903.  done
  1904.  exec <&4
  1905.  
  1906. }
  1907.  
  1908. getvirtualdocroot()
  1909. {
  1910.  
  1911.  weconfigfile=$1
  1912.  configfile=$2
  1913.  
  1914.  virtweb=`echo  $weconfigfile | sed -e '
  1915.          s/:/:/
  1916.          tmulti
  1917.          s/.cnf$//
  1918.          s/.*[^0-9]//
  1919.          q
  1920.          :multi
  1921.          s/:[0-9]*.cnf$//'`
  1922.  virtweb=`basename $virtweb`
  1923.  
  1924.  case $configfile in
  1925.       *magnus*) n=0              
  1926.                 resourcefile=`echo $configfile | sed -e 's/magnus\.conf/obj.conf/'`  
  1927.                 exec 4<&0
  1928.                 exec <$resourcefile
  1929.                 echo
  1930.                 echo "Looking for Client block of $resourcefile..." 
  1931.                 
  1932.                 while read line
  1933.                 do 
  1934.                     uc_line=`echo $line | tr [a-z] [A-Z]`
  1935.                     case $uc_line in
  1936.                          *URLHOST*) virtname=`echo $line | sed -e '
  1937.                                              s/\"//g
  1938.                                              s/ *<.*= *//
  1939.                                              s/ *>.*//'` 
  1940.  
  1941.                                     if [ "$virtweb" = "$virtname" ]
  1942.                                     then
  1943.                                         echo "Found Client block.  Getting Document-Root and Subdir..."
  1944.                                         while read line
  1945.                                         do 
  1946.                                             uc_line=`echo $line | tr [a-z] [A-Z]`
  1947.                                             case $uc_line in
  1948.                                                   *DOCUMENT-ROOT*) docroot=`echo $line | sed -e '
  1949.                                                                     s/\"//g
  1950.                                                                     s/.* [Rr][)o][Oo][Tt]= *//
  1951.                                                                     s/ .*//'` 
  1952.                                                                  ;;
  1953.                                                          *SUBDIR*) userdir=`echo $line | sed -e '
  1954.                                                                     s/\"//g
  1955.                                                                     s/.* [Ss][Uu][Bb][Dd][Ii][Rr]= *//
  1956.                                                                     s/ .*//'` 
  1957.                                                                  ;;
  1958.                                                     \</CLIENT\>) break 
  1959.                                                                  ;;
  1960.                                             esac
  1961.                                         done 
  1962.                                     fi
  1963.                                     ;;
  1964.                     esac
  1965.                 done
  1966.                 exec <&4
  1967.                 ;;
  1968.              *) 
  1969.                 getHttpVirtualDirective $configfile $port DocumentRoot
  1970.                 docroot=$param
  1971.  
  1972.                 if [ "$docroot" = "" ]
  1973.                 then
  1974.                     echo "VirtualHost block does not contain DocumentRoot directive."
  1975.                     getHttpDirective $configfile ResourceConfig $port
  1976.                     if [ "$param" != "" ]
  1977.                     then
  1978.                         file=`basename $param`
  1979.                         resconffile="${configfiledir}${file}"
  1980.                     else
  1981.                         resconffile="${configfiledir}srm.conf"
  1982.                     fi
  1983.                     echo "Getting DocumentRoot from $resconffile."
  1984.                     getparam DocumentRoot $resconffile
  1985.                     docroot=$param
  1986.                 fi
  1987.  
  1988.                 getHttpVirtualDirective $configfile $port UserDir
  1989.                 userdir=$param
  1990.  
  1991.                 if [ "$userdir" = "" ]
  1992.                 then
  1993.                     echo "VirtualHost block does not contain UserDir directive."
  1994.                     getHttpDirective $configfile ResourceConfig $port
  1995.                     if [ "$param" != "" ]
  1996.                     then
  1997.                         file=`basename $param`
  1998.                         resconffile="${configfiledir}${file}"
  1999.                     else
  2000.                         resconffile="${configfiledir}srm.conf"
  2001.                     fi
  2002.                     echo "Getting UserDir from $resconffile."
  2003.                     getparam UserDir $resconffile
  2004.                     userdir=$param
  2005.                 fi
  2006.                 ;; 
  2007.  esac
  2008.  
  2009. }
  2010.  
  2011. error()
  2012. {
  2013.  #
  2014.  # Print an error message and exit the program
  2015.  #
  2016.  
  2017.  echo 
  2018.  echo "Exiting due to an error!  Please fix the error and try again." 
  2019.  echo 
  2020.  
  2021.  exit 1
  2022. }
  2023.  
  2024. getparam() {
  2025. #
  2026. # gets the value of parameters from the config file
  2027.     param=`egrep -i "^[ $TAB]*$1[ $TAB]" $2 | $awk '{print $2}'` || return 1
  2028.     return 0;
  2029. }
  2030. #
  2031. # This is the main part of the shell script.
  2032. #
  2033.  
  2034. initialize
  2035. step1
  2036. step2
  2037. step3
  2038. echo 
  2039.  
  2040. echo "Installation completed!  Exiting..." 
  2041. exit 0
  2042.  
  2043.  
  2044.